/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2021-10-10
 * Time: 16:02
 */
class TreeNode {
     int val;
     TreeNode left;
     TreeNode right;
     TreeNode() {}
     TreeNode(int val) {
         this.val = val;
     }
     TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
         this.left = left;
         this.right = right;
     }
}
public class BinaryTree {
    public int maxDepth(TreeNode root){
        if(root==null){
            return 0;
        }
        int leftHight=maxDepth(root.left);
        int ringhtHeight=maxDepth(root.right);
        return Math.max(leftHight,ringhtHeight)+1;
    }
    public boolean isBalanced(TreeNode root) {
        if(root==null){
            return true;
        }
        return(Math.abs(maxDepth(root.left)-maxDepth(root.right))<=1 && isBalanced(root.left) && isBalanced(root.right));
    }
}


